<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- qtquick-connection-editor-backend.qdoc -->
  <title>Managing C++ Backend Objects | Qt Creator Manual</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt Creator Manual</a></td><td >Managing C++ Backend Objects</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="index.html">Qt Creator Manual 4.11.1</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
  <link rel="prev" href="quick-property-bindings.html" />
  <link rel="next" href="quick-states.html" />
<p class="naviNextPrevious headerNavi">
<a class="prevPage" href="quick-property-bindings.html">Adding Bindings Between Properties</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="quick-states.html">Adding States</a>
</p><p/>
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Managing C++ Backend Objects</h1>
<span class="subtitle"></span>
<!-- $$$quick-connections-backend.html-description -->
<div class="descr"> <a name="details"></a>
<p>Many applications provide <a href="http://doc.qt.io/qt-5/qobject.html">QObject</a> objects implemented in C++ that work as a bridge between QML and C++. Such objects are typically registered with <code>qmlRegisterType</code> or <code>qmlRegisterSingletonType</code> and then used by QML to communicate with the C++ backend. Another example of such objects are the state machines created by the <a href="http://doc.qt.io/qt-5/qscxmlc.html">Qt SCXML Compiler</a>.</p>
<p>Backend objects in a QML file are accessible if the QML file contains the required imports. In addition, for a non-singleton <a href="http://doc.qt.io/qt-5/qobject.html">QObject</a>, a dynamic property that contains the <a href="http://doc.qt.io/qt-5/qobject.html">QObject</a> must be specified.</p>
<p>A <i>local</i> <a href="http://doc.qt.io/qt-5/qobject.html">QObject</a> is instantiated in the current <i>.qml</i> file, as follows:</p>
<pre class="cpp plain">

  property MyType myType: MyType {}.

</pre>
<p>Otherwise the property is just defined, as follows:</p>
<pre class="cpp plain">

  property MyType myType

</pre>
<p>To manage backend objects:</p>
<ol class="1" type="1"><li>In the <b>Connections</b> view, select the <b>Backends</b> tab to view accessible backend objects.<p class="centerAlign"><img src="images/qmldesigner-backends.png" alt="" /></p></li>
<li>Select the <img src="images/plus.png" alt="" /> (<b>Add</b>) button to add a backend object in the <b>Add New C++ Backend</b> dialog.</li>
<li>In the <b>Type</b> field, select the type of the backend <a href="http://doc.qt.io/qt-5/qobject.html">QObject</a> to add.</li>
<li>Select the <b>Define object locally</b> check box if the <a href="http://doc.qt.io/qt-5/qobject.html">QObject</a> is not registered as a singleton.</li>
<li>Select <b>OK</b> to add the required import and to create the property for a non-singleton object.</li>
</ol>
</div>
<!-- @@@quick-connections-backend.html -->
<p class="naviNextPrevious footerNavi">
<a class="prevPage" href="quick-property-bindings.html">Adding Bindings Between Properties</a>
<span class="naviSeparator">  &#9702;  </span>
<a class="nextPage" href="quick-states.html">Adding States</a>
</p>
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
